<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtpagecontrol.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Workorder_View_Frame extends Page
{
       public $btnAddLabor = null;
       public $cmbperformed = null;
       public $Label2 = null;
       public $cmbVendor = null;
       public $cmbEmp = null;
       public $edOther = null;
       public $chkComplete = null;
       public $chkComp = null;
       public $hfInitTrouble = null;
       public $hfTrouble = null;
       public $btnTrouble = null;
       public $edTrouble = null;
       public $Label3 = null;
       public $lblkm = null;
       public $lblOrderNo = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $lblod = null;
       public $lblordernum = null;
       public $Label12 = null;
       public $JSValidate = null;
       public $hfError = null;
       public $hfStartOdometer = null;
       public $hfTrackBy = null;
       public $LabelAttach = null;
       public $edKmRun = null;
       public $JTDivAccount = null;
       public $JTGroupBox2 = null;
       public $btnAddAccount = null;
       public $btnDelAccount = null;
       public $edAccount = null;
       public $listAccount = null;
       public $JTDivServiced = null;
       public $JTGroupBox3 = null;
       public $btnAddServiced = null;
       public $btnDelServiced = null;
       public $edServiced = null;
       public $listServiced = null;
       public $JTDivDescription = null;
       public $JTGroupBox4 = null;
       public $btnAddDescription = null;
       public $btnDelDescription = null;
       public $edDescription = null;
       public $listDescription = null;
       public $lblFullDescription = null;
       public $lblDescription = null;
       public $hfType = null;
       public $hfAttachment = null;
       public $lblServiced = null;
       public $edTax = null;
       public $lblTax = null;
       public $lbComputedlTax = null;
       public $edComputedTax = null;
       public $chkLabor = null;
       public $chkParts = null;
       public $chkMisc = null;
       public $JTJavaScript10 = null;
       public $btnAddMisc = null;
       public $JTFrameMisc = null;
       public $btnParts = null;
       public $JTFrameParts = null;
       public $JTFrameLabor = null;
       public $JTPageControl1 = null;
       public $btnCancel = null;
       public $btnUpdate = null;
       public $btnShowServiced = null;
       public $btnShowDescription = null;
       public $compid = null;
       public $JTJavaScript9 = null;
       public $JTJavaScript8 = null;
       public $JTJavaScript7 = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $btnShowAccount = null;
       public $Label1 = null;
       public $UploadPDF = null;
       public $memoRemarks = null;
       public $JTGroupBox1 = null;
       public $lblTotal = null;
       public $edTotal = null;
       public $lblDiscount = null;
       public $edDiscount = null;
       public $edParts = null;
       public $lblParts = null;
       public $edMisc = null;
       public $lblMisc = null;
       public $edLabor = null;
       public $lblLabor = null;
       public $jtStatus = null;
       public $chkRecall = null;
       public $chkWarr = null;
       public $lblMaint1 = null;
       public $memoFullDescription = null;
       public $cmbDescription = null;
       public $cmbAcct = null;
       public $lblAcct = null;
       public $cmbServiced = null;
       public $cmbDriver = null;
       public $edOdometer = null;
       public $lblOdometer = null;
       public $lblDriver = null;
       public $edOrderNo = null;
       public $dpCompletionDate = null;
       public $lblCompletionDate = null;
       public $dpCreationDate = null;
       public $lblCreationDate = null;
       public $lblPDF = null;
       public $imgBack = null;
       public $Image3 = null;
       public $hiddenVeh = null;
       public $hiddenWorkOrder = null;
       public $JTSiteTheme1 = null;
       function cmbperformedJSChange($sender, $params)
       {

       ?>
       var service = document.getElementById('cmbperformed').value;
       var vend = document.getElementById('cmbVendor_outer');
       var emp = document.getElementById('cmbEmp_outer');
       var other = document.getElementById('edOther_outer');

       if(service=='employee')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'hidden';
       vend.style.left = '311px';
       document.getElementById('edOther_outer').style.visibility = 'hidden';
       other.style.left = '311px';
       document.getElementById('cmbEmp_outer').style.visibility = 'visible';
       emp.style.left = '121px';
       }

       if(service=='vendor')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'visible';
       vend.style.left = '121px';
       document.getElementById('edOther_outer').style.visibility = 'hidden';
       other.style.left = '311px';
       document.getElementById('cmbEmp_outer').style.visibility = 'hidden';
       emp.style.left = '311px';
       }

       if(service=='other')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'hidden';
       vend.style.left = '311px';
       document.getElementById('edOther_outer').style.visibility = 'visible';
       other.style.left = '121px';
       document.getElementById('cmbEmp_outer').style.visibility = 'hidden';
       emp.style.left = '311px';
       }

       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       window.close();
       <?php

       }


       function btnTroubleJSClick($sender, $params)
       {

       ?>
       var win_height = 550;
       var win_width = 610;
       var height = window.opener.outerHeight;
       var width = window.opener.outerWidth;
       var top = Math.round((height-win_height)/2);
       var left = Math.round((width-win_width)/2);

       veh_id = document.getElementById("hiddenVeh").value;
       tids = document.getElementById("hfInitTrouble").value;
       window.open("select_trouble.php?tids="+tids+"&veh_id="+veh_id, 'Select_Trouble', 'location=no,height='+win_height+',width='+win_width+',top='+top+',left='+left);
       <?php

       }

       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }


       function edOdometerJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edOdometer','lblod');
       <?php

       }

       function edOrderNoJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edOrderNo','lblordernum');
       <?php

       }

       function edKmRunJSKeyUp($sender, $params)
       {

       ?>
       var start_odometer = document.getElementById('hfStartOdometer');
       var edit_odometer = document.getElementById('edOdometer');
       var km_run = document.getElementById('edKmRun');

       edit_odometer.value = Number(km_run.value) + Number(start_odometer.value);
       <?php

       }

       function edOdometerJSKeyUp($sender, $params)
       {

       ?>
       var start_odometer = document.getElementById('hfStartOdometer');
       var edit_odometer = document.getElementById('edOdometer');
       var km_run = document.getElementById('edKmRun');

       km_run.value = Number(edit_odometer.value) - Number(start_odometer.value);
       <?php

       }
       function btnAddMiscJSClick($sender, $params)
       {

       ?>
       var wo=document.getElementById('hiddenWorkOrder').value;
       var veh=document.getElementById('hiddenVeh').value;

       window.open("veh_misc_create.php?veh="+veh+"&WO="+wo,"Window1","menubar=no,width=664,height=336,left=350,top=250,toolbar=no");

       <?php

       }

       function chkLaborJSChange($sender, $params)
       {

       ?>
       this.setWODetails();
       <?php

       }

       function chkMiscJSChange($sender, $params)
       {

       ?>
       this.setWODetails();
       <?php

       }

       function chkPartsJSChange($sender, $params)
       {

       ?>
       this.setWODetails();
       <?php

       }

       function btnPartsJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var wo=document.getElementById('hiddenWorkOrder').value;
       var veh=document.getElementById('hiddenVeh').value;

       window.open("veh_parts_create.php?veh="+veh+"&WO="+wo,"Window1","menubar=no,width=664,height=336,left=350,top=250,toolbar=no");
       <?php

       }

       function btnAddLaborJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var wo=document.getElementById('hiddenWorkOrder').value;
       var veh=document.getElementById('hiddenVeh').value;

       window.open("veh_laborline_create.php?veh="+veh+"&WO="+wo,"Window1","menubar=no,width=664,height=336,left=350,top=250,toolbar=no");
       <?php
       }

       function btnDelDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DescIndex = document.getElementById('listDescription').selectedIndex;
       var DescValue = document.getElementById('listDescription')[DescIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxDesc3(DescValue,comp);
       <?php

       }

       function btnAddDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddesc = document.getElementById('edDescription').value;
       var compider = document.getElementById('compid').value;
       AjaxDesc2(adddesc,compider);
       document.Vehicle_Workorder_Edit_Frame.edDescription.value = "";
       <?php

       }

       function btnShowDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDescription').Show();
       document.Vehicle_Workorder_Edit_Frame.edDescription.value = "";
       <?php

       }

       function btnAddServicedJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addserviced = document.getElementById('edServiced').value;
       var compider = document.getElementById('compid').value;
       AjaxServiced2(addserviced,compider);
       document.Vehicle_Workorder_Edit_Frame.edServiced.value = "";
       <?php

       }

       function btnDelServicedJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var ServicedIndex = document.getElementById('listServiced').selectedIndex;
       var ServicedValue = document.getElementById('listServiced')[ServicedIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxServiced3(ServicedValue,comp);
       <?php

       }


       function btnShowServicedJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivServiced').Show();
       document.Vehicle_Workorder_Edit_Frame.edServiced.value = "";
       <?php

       }


       function btnDelAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var AccountIndex = document.getElementById('listAccount').selectedIndex;
       var AccountValue = document.getElementById('listAccount')[AccountIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxAccount3(AccountValue,comp);
       <?php

       }


       function btnAddAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addaccount = document.getElementById('edAccount').value;
       var compider = document.getElementById('compid').value;
       AjaxAccount2(addaccount,compider);
       document.Vehicle_Workorder_Edit_Frame.edAccount.value = "";
       <?php

       }

       function btnShowAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivAccount').Show();
       document.Vehicle_Workorder_Edit_Frame.edAccount.value = "";
       <?php

       }

       function lblPDFJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var wo = document.getElementById('hiddenWorkOrder').value;
       var attachment = document.getElementById('hfAttachment').value;
       //alert(wo);
       //window.open("photo/pdf/pdf"+wo+".pdf","Window1","menubar=no,width=730,height=660,left=450,top=250,toolbar=no");
       window.open("photo/pdf/"+attachment,"Window1","menubar=no,width=730,height=660,left=450,top=250,toolbar=no");
       //window.open("photo/pdf/pdf23.pdf","Window1","menubar=no,width=430,height=360,left=450,top=250,toolbar=no");
       <?php

       }



       function Vehicle_Workorder_View_FrameJSLoad($sender, $params)
       {

       ?>
       var service = document.getElementById('cmbperformed').value;
       var vend = document.getElementById('cmbVendor_outer');
       var emp = document.getElementById('cmbEmp_outer');
       var other = document.getElementById('edOther_outer');

       if(service=='employee')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'hidden';
       vend.style.left = '311px';
       document.getElementById('edOther_outer').style.visibility = 'hidden';
       other.style.left = '311px';
       document.getElementById('cmbEmp_outer').style.visibility = 'visible';
       emp.style.left = '121px';
       }

       if(service=='vendor')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'visible';
       vend.style.left = '121px';
       document.getElementById('edOther_outer').style.visibility = 'hidden';
       other.style.left = '311px';
       document.getElementById('cmbEmp_outer').style.visibility = 'hidden';
       emp.style.left = '311px';
       }

       if(service=='other')
       {
       document.getElementById('cmbVendor_outer').style.visibility = 'hidden';
       vend.style.left = '311px';
       document.getElementById('edOther_outer').style.visibility = 'visible';
       other.style.left = '121px';
       document.getElementById('cmbEmp_outer').style.visibility = 'hidden';
       emp.style.left = '311px';
       }

       document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edParts.value)-
       Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);

       <?php

       }

       function edPartsJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edParts.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edComputedTax.value) -
       Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);
       <?php

       }

       function edLaborJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edParts.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edComputedTax.value) -
       Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);
       <?php

       }

       function edComputedTaxJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edParts.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edComputedTax.value) -
       Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);
       <?php

       }

       function edDiscountJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       //document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       //Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       //Number(document.Vehicle_Workorder_Edit_Frame.edParts.value) +
       //Number(document.Vehicle_Workorder_Edit_Frame.edComputedTax.value) -
       //Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);
       this.setWODetails();
       <?php

       }

       function edMiscJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Workorder_Edit_Frame.edTotal.value = Number(document.Vehicle_Workorder_Edit_Frame.edLabor.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edMisc.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edParts.value) +
       Number(document.Vehicle_Workorder_Edit_Frame.edComputedTax.value) -
       Number(document.Vehicle_Workorder_Edit_Frame.edDiscount.value);
       <?php

       }

       function JTPlatinumVehicleLaborlineShow($sender, $params)
       {
       $veh_id = $this->hiddenVeh->getValue();
       $query1 = "select * from veh_laborline_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$veh_id."'";
       $result = mysql_query($query1)or die(mysql_error());

       $arr = array();
       while($row = mysql_fetch_array($result))
       {

       $labor_unit = "<a href=veh_laborline_edit.php?veh=".$veh_id."&laborline=".$row['labor_id'].">".$row['labor_unit']."</a>";


       $arr[] = array(
                        'Units' => $labor_unit,
                        'Cost/Unit' => $row['cost'],
                        'Description' => $row['description']
                        );
       }

       $this->JTPlatinumVehicleLaborline->setCellData($arr);


       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }


       function Vehicle_Workorder_View_FrameCreate($sender, $params)
       {
       $this->hfError->setValue('0');

       $this->lblod->Caption = '';
       $this->lblordernum->Caption = '';

       $this->compid->Value = $_SESSION['company_id'];
       $this->hfType->setValue('edit');
       $veh_id = base64_decode($_GET['veh']);
       $veh_workorder = base64_decode($_GET['WO']);

       $this->hiddenVeh->setValue($veh_id);
       $this->hiddenWorkOrder->setValue($veh_workorder);

       $this->JTFrameLabor->setURL('veh_laborline_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWorkOrder->getValue().'&type='.$this->hfType->getValue().'&form=summary');
       $this->JTFrameParts->setURL('veh_parts_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWorkOrder->getValue().'&type='.$this->hfType->getValue().'&form=summary');
       $this->JTFrameMisc->setURL('veh_misc_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWorkOrder->getValue().'&type='.$this->hfType->getValue().'&form=summary');

       //$this->JTGroupBox1->StyleFont=white;

       /*$result_laborline = mysql_query("select * from veh_laborline_tbl where vehicle_id='".$this->hiddenVeh->getValue()."' and workorder='".$this->hiddenWorkOrder->getValue()."'");
       $row_laborline = mysql_fetch_array($result_laborline);*/
       if($_SESSION['access_vehicle']==1)
       {
       $this->btnCancel->Visible=false;
       $this->btnUpdate->Visible=false;
       $this->btnAddLabor->Visible=false;
       $this->btnParts->Visible=false;
       $this->btnAddMisc->Visible=false;
       }

       if($_SESSION['access_vehicle']==2)
       {
       $this->btnCancel->Visible=true;
       $this->btnUpdate->Visible=true;
       //$this->btnAddLabor->Visible=true;
       //$this->btnParts->Visible=true;
       //$this->btnAddMisc->Visible=true;
       }



       $total_labor = mysql_query("SELECT SUM(total) as sum_labor FROM veh_laborline_tbl where workorder='".$this->hiddenWorkOrder->getValue()."' and warranty='0'")or die(mysql_error());
       $row_labor = mysql_fetch_array($total_labor);

       $this->edLabor->Text=$row_labor['sum_labor'];


       $total_parts = mysql_query("SELECT SUM(amount) as sum_parts FROM veh_parts_tbl where workorder='".$this->hiddenWorkOrder->getValue()."' and warranty='0'")or die(mysql_error());
       $row_parts = mysql_fetch_array($total_parts);

       $this->edParts->Text=$row_parts['sum_parts'];




       $result_odometer = mysql_query("select * from vehicle_tbl where vehicle_id='".$this->hiddenVeh->getValue()."'");
       $row_od = mysql_fetch_array($result_odometer);
       $this->edOdometer->Text=$row_od['curr_tracking_value'];

       $label_od = $row_od['track_by'];
       $stard_odometer = $row_od['tracking_value'];
       //$this->hfTrackBy->setValue($label_od);
       $this->hfStartOdometer->setValue($stard_odometer);
       if ($label_od=='distance')
        {
        $this->lblOdometer->Caption = '*Odometer:';
        $this->lblkm->Visible = true;
        $this->edKmRun->Visible = true;

        $this->edOdometer->Text=$row_od['curr_tracking_value'];
        }
       if ($label_od=='hours')
        {
        $this->lblOdometer->Caption = '*Hours:';
        $this->lblkm->Visible = false;
        $this->edKmRun->Visible = false;

        $this->edOdometer->Text=$row_od['curr_hours'];
        }


       //WO QUERY
       $query_wo = "select * from veh_workorder_tbl where vehicle_id='".$this->hiddenVeh->getValue()."'and workorder_id='".$this->hiddenWorkOrder->getValue()."'";
       $result_wo = mysql_query($query_wo)or die(mysql_error());
       $row_wo = mysql_fetch_array($result_wo);

       $tracking = $row_wo['track_by'];
       $this->hfTrackBy->setValue($tracking);

       $this->cmbDriver->ItemIndex = $row_wo['driver'];
       $result_driver = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."' and veh_op='1'");
       //$this->cmbDriver->AddItem('--Select--',null,null);
       while($row_driver = mysql_fetch_array($result_driver))
       {
            $this->cmbDriver->AddItem($row_driver['lname'].','.$row_driver['fname'], null, $row_driver['autoid']);
       }


        $this->cmbAcct->ItemIndex = $row_wo['account'];
        $result_account = mysql_query("select * from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' and category='accounts'");
        //$this->cmbAcct->AddItem('--Select--',null,null);
        while($row_account = mysql_fetch_array($result_account))
        {
            $this->cmbAcct->AddItem($row_account['value'], null, $row_account['value']);
        }

         //list account
        $result_a = mysql_query("select value from lookup_expense_tbl where company_id = '".$_SESSION['company_id']."' AND category='accounts'");

        while($row_a = mysql_fetch_array($result_a))
        {
            $this->listAccount->AddItem($row_a['value'], null, $row_a['value']);
        }

        $this->cmbDescription->ItemIndex = $row_wo['description'];
        $result_desc = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' and category='descriptions'");
        //$this->cmbDescription->AddItem('--Select--',null,null);
        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbDescription->AddItem($row_desc['value'], null, $row_desc['value']);
        }


        //list description
        $result_d = mysql_query("select value from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='descriptions'");

        while($row_d = mysql_fetch_array($result_d))
        {
            $this->listDescription->AddItem($row_d['value'], null, $row_d['value']);
        }



       $this->cmbEmp->Clear();
       $result_emp = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_emp = mysql_fetch_array($result_emp))
       {
            $this->cmbEmp->AddItem($row_emp['lname'].','.$row_emp['fname'], null, $row_emp['lname'].','.$row_emp['fname']);
       }

       $this->cmbVendor->Clear();
       $result_vendor = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_vendor = mysql_fetch_array($result_vendor))
       {
            $this->cmbVendor->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
       }


        $this->cmbperformed->ItemIndex = $row_wo['service_provider'];

        if($row_wo['service_provider']=="vendor")
        {
        $this->cmbVendor->ItemIndex = $row_wo['service_name'];
        }

        if($row_wo['service_provider']=="employee")
        {
        $this->cmbEmp->ItemIndex = $row_wo['service_name'];
        }

        if($row_wo['service_provider']=="other")
        {
        $this->edOther->Text = $row_wo['service_name'];
        }
        /*$result_ServiceProvider = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' and category='serviced by'");
        //$this->cmbServiced->AddItem('--Select--',null,null);
        while($row_ServiceProvider = mysql_fetch_array($result_ServiceProvider))
        {
            $this->cmbServiced->AddItem($row_ServiceProvider['value'], null, $row_ServiceProvider['value']);
        }*/
        //$this->cmbServiced->AddItem('None',null,null);
       //list serviced by
        $result_s = mysql_query("select value from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND category='serviced by'");

        while($row_s = mysql_fetch_array($result_s))
        {
            $this->listServiced->AddItem($row_s['value'], null, $row_s['value']);
        }



       //$this->lblPDF->Caption=$row_wo['attachment'];

       if($row_wo['attachment']!='')
       {
       $this->lblPDF->Caption=$row_wo['attachment'];
       $this->hfAttachment->setValue($row_wo['attachment2']);
       $this->lblPDF->Visible=true;
       $this->lblPDF->Font->Color='yellow';
       $this->LabelAttach->Visible=true;
       }


       if($row_wo['attachment']=='' || $row_wo['attachment']==null)
       {
       //die($row_wo['attachment']);
       $this->lblPDF->Visible=false;
       $this->lblPDF->Caption=$row_wo['attachment'];
       $this->LabelAttach->Visible=false;
       }


        if($row_wo['warr']=='1')
       {
       $this->chkWarr->Checked=true;
       }
       else
       {
       $this->chkWarr->Checked=false;
       }


        if($row_wo['backjob']=='1')
       {
       $this->chkRecall->Checked=true;
       }
       else
       {
       $this->chkRecall->Checked=false;
       }


       if($row_wo['complete']=='1')
       {
       $this->chkComplete->Checked=true;
       }
       else
       {
       $this->chkComplete->Checked=false;
       }

        if($row_wo['ch_Labor']=='1')
       {
       $this->chkLabor->Checked=true;
       }
       else
       {
       $this->chkLabor->Checked=false;
       }

       if($row_wo['ch_Misc']=='1')
       {
       $this->chkMisc->Checked=true;
       }
       else
       {
       $this->chkMisc->Checked=false;
       }

       if($row_wo['ch_Parts']=='1')
       {
       $this->chkParts->Checked=true;
       }
       else
       {
       $this->chkParts->Checked=false;
       }

       //FOR TROUBLE
       if($veh_id!='' && $veh_id!=null)
       {
        $this->hfInitTrouble->setValue($row_wo['trouble_ids']);
        $this->hfTrouble->setValue($row_wo['trouble_ids']);
        if($this->hfTrouble->getValue()!="")
        {
         $this->edTrouble->Text = "added trouble";
        }
       }

       $this->dpCreationDate->Text = $row_wo['creation_date'];
       $this->dpCompletionDate->Text = $row_wo['completion_date'];
       $this->edOrderNo->Text = $row_wo['order_num'];
       $this->edOdometer->Text = $row_wo['odometer'];
       $this->memoFullDescription->Text = $row_wo['full_desc'];

       $this->memoRemarks->Clear();
       $this->memoRemarks->Text = $row_wo['maint_custom1'];
       //$this->edLabor->Text = $row['labor'];
       $this->edMisc->Text = $row_wo['misc'];
       //$this->edParts->Text = $row['parts'];
       $this->edDiscount->Text = $row_wo['discount'];
       $this->edTax->Text = $row_wo['tax'];
       $this->edComputedTax->Text = $row_wo['computed_tax'];
       $this->edTotal->Text = $row_wo['total'];


       $this->edTax->Hidden=true;
       $this->lblTax->Hidden=true;
       $this->chkLabor->Hidden=true;
       $this->chkMisc->Hidden=true;
       $this->chkParts->Hidden=true;



       $result_billing =mysql_query("select * from company_billing_tbl where company_id='".$_SESSION['company_id']."'");
       $row_billing = mysql_fetch_array($result_billing);
       $label_billing = $row_billing['automatically_calculate'];
       if ($label_billing=='1')
       {
       $this->edTax->Hidden=false;
       $this->lblTax->Hidden=false;
       $this->edTax->Text=$row_billing['percent'];
       $this->chkLabor->Hidden=false;
       $this->chkLabor->Caption="";
       $this->chkMisc->Hidden=false;
       $this->chkMisc->Caption="";
       $this->chkParts->Hidden=false;
       $this->chkParts->Caption="";
       }
       else
       {
       $this->edTax->Hidden=true;
       $this->lblTax->Hidden=true;
       $this->chkLabor->Hidden=true;
       $this->chkMisc->Hidden=true;
       $this->chkParts->Hidden=true;
       }

       $label_billing = $row_billing['labor'];
       if($label_billing=='1')
       {
       $this->chkLabor->Checked=true;
       }
       else
       {
       $this->chkLabor->Checked=false;
       }

       $label_billing = $row_billing['labor'];
       if($label_billing=='1')
       {
       $this->chkLabor->Checked=true;
       }
       else
       {
       $this->chkLabor->Checked=false;
       }

       $label_billing = $row_billing['miscellaneous'];
       if($label_billing=='1')
       {
       $this->chkMisc->Checked=true;
       }
       else
       {
       $this->chkMisc->Checked=false;
       }

       $label_billing = $row_billing['parts'];
       if($label_billing=='1')
       {
       $this->chkParts->Checked=true;
       }
       else
       {
       $this->chkParts->Checked=false;
       }




       $this->imgBack->setLink('veh_workorder_list.php?veh='.$this->hiddenVeh->getValue());

       //die('x'.$this->chkParts->Checked.'x'.$this->chkLabor->Checked.'x');
       if($this->chkLabor->Checked==1 && $this->chkParts->Checked==0)
       {
       $this->edComputedTax->Text=($this->edLabor->Text)*(($this->edTax->Text)/100);
       }
       else if($this->chkParts->Checked==1 && $this->chkParts->Checked==0)
       {
       $this->edComputedTax->Text=($this->edParts->Text)*(($this->edTax->Text)/100);
       }
       else if($this->chkLabor->Checked==1 && $this->chkParts->Checked==1)
       {
       $labor = ($this->edLabor->Text)*(($this->edTax->Text)/100);
       $parts = ($this->edParts->Text)*(($this->edTax->Text)/100);
       $ans = $labor+$parts;
       $this->edComputedTax->Text=$labor+$parts;

       }




       }





       function btnUpdateClick($sender, $params)
       {
       $this->validateRequired($this->edOrderNo->Text, 'lblordernum');
       $this->validateRequired($this->edOdometer->Text, 'lblod');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {


       if ($this->chkLabor->Checked==true)
       {
       $chkLabor ='1';
       }
       else
       {
       $chkLabor='0';
       }

       if ($this->chkMisc->Checked==true)
       {
       $chkMisc ='1';
       }
       else
       {
       $chkMisc='0';
       }

       if ($this->chkParts->Checked==true)
       {
       $chkParts ='1';
       }
       else
       {
       $chkParts='0';
       }

       if ($this->chkWarr->Checked==true)
       {
       $chkWarr ='1';
       }
       else
       {
       $chkWarr='0';
       }


       if ($this->chkRecall->Checked==true)
       {
       $chkRecall ='1';
       }
       else
       {
       $chkRecall='0';
       }


       if ($this->chkComplete->Checked==true)
       {
       $chkComplete ='1';
       }
       else
       {
       $chkComplete='0';
       }


       $serviced = $this->cmbperformed->getItemIndex();

       if($serviced=="vendor")
       {
       $service_name = $this->cmbVendor->getItemIndex();
       }

       if($serviced=="employee")
       {
       $service_name = $this->cmbEmp->getItemIndex();
       }

       if($serviced=="other")
       {
       $service_name = $this->edOther->Text;
       }



       $service = $this->cmbServiced->getItemIndex();
       $result_service = mysql_query("select value from lookup_workorder_tbl where company_id = '".$_SESSION['company_id']."' AND id='".$service."'");
       $row_service = mysql_fetch_array($result_service);

       //complete='".$chkComplete."'
       if($this->UploadPDF->FileExt=='')
       {
       $query_update = "UPDATE veh_workorder_tbl SET
       trouble_ids='".$this->hfTrouble->getValue()."',
       creation_date='".$this->dpCreationDate->Text."',
       completion_date='".$this->dpCompletionDate->Text."',
       driver = '".$this->cmbDriver->getItemIndex()."',
       order_num='".$this->edOrderNo->Text."',
       odometer='".$this->edOdometer->Text."',
       service_provider='".$this->cmbperformed->getItemIndex()."',
       service_name='".$service_name."',
       account='".$this->cmbAcct->getItemindex()."',
       description='".$this->cmbDescription->getItemindex()."',
       full_desc='".$this->memoFullDescription->Text."',
       maint_custom1='".$this->memoRemarks->Text."',
       labor='".$this->edLabor->Text."',
       misc='".$this->edMisc->Text."',
       parts='".$this->edParts->Text."',
       discount='".$this->edDiscount->Text."',
       tax='".$this->edTax->Text."',
       computed_tax='".$this->edComputedTax->Text."',
       total='".$this->edTotal->Text."',
       ch_labor='".$chkLabor."',
       ch_misc='".$chkMisc."',
       ch_parts='".$chParts."',
       warr = '".$chkWarr."',
       backjob='".$chkRecall."'
       WHERE vehicle_id='".$this->hiddenVeh->getValue()."'and workorder_id ='".$this->hiddenWorkOrder->getValue()."'";
       mysql_query($query_update) or die(mysql_error());
       }

       if($this->UploadPDF->FileExt!='')
       {
       $query_update = "UPDATE veh_workorder_tbl SET
       trouble_ids='".$this->hfTrouble->getValue()."',
       creation_date='".$this->dpCreationDate->Text."',
       completion_date='".$this->dpCompletionDate->Text."',
       driver = '".$this->cmbDriver->getItemIndex()."',
       order_num='".$this->edOrderNo->Text."',
       odometer='".$this->edOdometer->Text."',
       service_provider='".$this->cmbperformed->getItemIndex()."',
       service_name='".$service_name."',
       account='".$this->cmbAcct->getItemindex()."',
       description='".$this->cmbDescription->getItemindex()."',
       full_desc='".$this->memoFullDescription->Text."',
       maint_custom1='".$this->memoRemarks->Text."',
       labor='".$this->edLabor->Text."',
       misc='".$this->edMisc->Text."',
       parts='".$this->edParts->Text."',
       discount='".$this->edDiscount->Text."',
       tax='".$this->edTax->Text."',
       computed_tax='".$this->edComputedTax->Text."',
       total='".$this->edTotal->Text."',
       ch_labor='".$chkLabor."',
       ch_misc='".$chkMisc."',
       ch_parts='".$chParts."',
       warr = '".$chkWarr."',
       backjob='".$chkRecall."',
       attachment='".$this->UploadPDF->FileName."',
       attachment2='pdf".$this->hiddenWorkOrder->getValue().'.'.$this->UploadPDF->FileExt."'
       WHERE vehicle_id='".$this->hiddenVeh->getValue()."'and workorder_id ='".$this->hiddenWorkOrder->getValue()."'";
       mysql_query($query_update) or die(mysql_error());

       $this->UploadPDF->moveUploadedFile("photo/pdf/pdf".$this->hiddenWorkOrder->getValue().".".$this->UploadPDF->FileExt);
       }

       //FOR TROUBLE USED FLAG
       $trouble_ids = explode(',',$this->hfTrouble->getValue());
       foreach($trouble_ids as $trouble_id)
       {
        $query_up_trouble = "UPDATE veh_trouble_tbl SET flag_used='1' WHERE
        autoid='".$trouble_id."'";
        mysql_query($query_up_trouble) or die("UPDATE TROUBLE USED FLAG ".mysql_error());
       }

       $initial = $this->hfInitTrouble->getValue();
       $inits = explode(',',$initial);
       foreach($inits as $init)
       {
        $ctr_trou = 0;
        foreach($trouble_ids as $trouble_id)
        {
         if($init==$trouble_id)
         {
         $ctr_trou++;
         }
        }
        if($ctr_trou==0)
        {
         $query_up_trouble2 = "UPDATE veh_trouble_tbl SET flag_used='0' WHERE
         autoid='".$init."'";
         mysql_query($query_up_trouble2) or die("UPDATE TROUBLE USED FLAG 2".mysql_error());
        }
       }



       $query_track_val = "SELECT * FROM vehicle_tbl WHERE vehicle_id='".$this->hiddenVeh->getValue()."'";
       $result_track_val = mysql_query($query_track_val) or die("SELECT CURR TRACKING VALUE ".mysql_error());
       $row_track_val = mysql_fetch_array($result_track_val);

       $track_by = $this->hfTrackBy->getValue();
       $edit_odometer = $this->edOdometer->Text;
       if($track_by=='distance')
       {
        if($edit_odometer>$row_track_val['curr_tracking_value'])
        {
        $query_up_curr = "UPDATE vehicle_tbl SET curr_tracking_value='".$edit_odometer."' WHERE vehicle_id='".$this->hiddenVeh->getValue()."'";
        mysql_query($query_up_curr) or die("UPDATE CURRENT TRACKING VALUE ".mysql_error());
        }
       }
       if($track_by=='hours')
       {
        if($edit_odometer>$row_track_val['curr_hours'])
        {
        $query_up_curr = "UPDATE vehicle_tbl SET curr_hours='".$edit_odometer."' WHERE vehicle_id='".$this->hiddenVeh->getValue()."'";
        mysql_query($query_up_curr) or die("UPDATE CURRENT TRACKING VALUE ".mysql_error());
        }
       }
       //redirect('veh_workorder_list.php?veh='.$this->hiddenVeh->getValue());
       echo "<script type='text/javascript'>
       window.opener.location.reload();
       window.close();
       </script>";
       }
       }



       function btnCancelClick($sender, $params)
       {
       redirect('veh_workorder_list.php?veh='.$this->hiddenVeh->getValue());
       }

}

global $application;

global $Vehicle_Workorder_View_Frame;

//Creates the form
$Vehicle_Workorder_View_Frame=new Vehicle_Workorder_View_Frame($application);

//Read from resource file
$Vehicle_Workorder_View_Frame->loadResource(__FILE__);

//Shows the form
$Vehicle_Workorder_View_Frame->show();

?>